<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<style>
#cfdd_manage_div_1,#cfdd_manage_div_2,#cfdd_manage_div_3,#cfdd_manage_div_4,#cfdd_manage_div_5{
	padding: 10px;
}
#msg2 {
	height: 20px;
	color: red;
}
.modal-content {
	margin-top: 250px;
}
#change_title{
	color:red;
}
#cfdd_manage_div_detail{
	padding:30px 50px;
}
#cfdd_manage_div_table{
	margin-top:15px;
}
#cfdd_manage_div_table {
	text-align: center;
}
</style>
<body>
	<div id="cfdd_manage_div" style="display: none" class="row">
				<div id="cfdd_manage_div_detail">
					<button type="button" class="btn btn-info" data-toggle="modal" data-target="#btn_add_cfdd">新增存放地点</button>
					<table id="cfdd_manage_div_table" class="table table-hover">
						<thead>
							<tr style="text-align: center;">
								<th style="text-align: center;">序号</th>
								<th style="text-align: center;">存放地点</th>
								<th style="text-align: center;">操作</th>
								<th style="text-align: center; display: none">id</th>
							</tr>
						</thead>
						<tbody id="cfdd_manage_div_table_tbody">
							
						</tbody>
					</table>
				</div>
			</div>
<!-- 新增存放地点Modal -->
	<div class="modal fade" id="btn_add_cfdd" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title" id="change_title">存放地点</h4>
				</div>
				<form id="btn_add_cfdd_form">
					<div class="modal-body" id="change_div">
						<div id="cfdd_manage_div_1" class="input-group">
							<span class="input-group-addon">存放地点:</span> <input type="text"
								class="form-control" placeholder="请输入存放地点名称"
								aria-describedby="basic-addon1" required="required"
								name="cfdd_name">
						</div>
						<div id="msg2">
							<span class="msg2_span1"></span>
							<span class="msg2_span2"></span>
						</div>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
						<button type="submit" class="btn btn-primary">添加</button>
					</div>
				</form>
			</div>
		</div>
		</div>
						<!-- btn修改洗衣方法Modal -->
	<div class="modal fade" id="btn_change_cfdd" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title" id="change_title">修改用户</h4>
				</div>
				<form id="btn_change_cfdd_form">
					<div class="modal-body" id="change_div">
						<div id="cfdd_manage_div_1" class="input-group">
							<span class="input-group-addon">方法名:</span> <input type="text"
								class="form-control" placeholder="请输入方式名称名"
								aria-describedby="basic-addon1" required="required"
								name="cfdd_name">
						</div>
						<div id="cfdd_manage_div_2" class="input-group" style="display: none">
							<span class="input-group-addon">id:</span> <input type="text"
								class="form-control"
								aria-describedby="basic-addon1" required="required"
								name="cfdd_id" disabled="disabled" >
						</div>
						<div id="msg2">
							<span class="msg2_span1"></span>
							<span class="msg2_span2"></span>
						</div>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
						<button type="submit" class="btn btn-primary">修改</button>
					</div>
				</form>
			</div>
		</div>
		</div>
</body>
<script type="text/javascript">
function btnDeleteCfdd(obj){
	var id = $(obj).parent().parent().children("td:eq(3)").html();
	$.ajax({
		url : "btn_delete_cfdd", //请求的url地址
		contentType : "application/json; charset=utf-8",
		dataType : "json", //返回格式为json
		type : "POST", //请求方式
		data : JSON.stringify({
			'id':id
		}),
		beforeSend : function() {
		},
		success : function(data) {
			if (data.isSuccess) {
				cfddManageQuery();
			} else {
				alert("删除失败...");
			}
		},
		complete : function() {
			//请求完成的处理
			//alert("请求完成");
		},
		error : function(req) {
			alert("  error  请联系开发人员 ！");
		}
	});
}
$("#btn_change_cfdd_form").submit(function() {
	$(".msg2_span1").html("");
	$(".msg2_span2").html("");
	$.ajax({
		url : "change_cfdd", //请求的url地址
		contentType : "application/json; charset=utf-8",
		dataType : "json", //返回格式为json
		type : "POST", //请求方式
		data : JSON.stringify({
			'cfdd' : $(
					"#btn_change_cfdd_form input[ name='cfdd_name' ] ")
					.val(),
			'id':$(
			"#btn_change_cfdd_form input[ name='cfdd_id' ] ")
			.val(),
		}),
		beforeSend : function() {
		},
		success : function(data) {
			if (data.isSuccess) {
				$(".msg2_span1").html("修改成功...");
				$("#btn_change_cfdd").modal('hide');
				cfddManageQuery();
			} else {
				$(".msg2_span1").html("修改失败,该地点已经存在...");
			}
		},
		error : function(req) {
			alert("  error  请联系开发人员 ！");
		}
	});
	return false;
});
function btnChangeCfdd(obj){
	$(".msg2_span1").html("");
	$("#cfdd_manage_div_1 input").val($(obj).parent().parent().children("td:eq(1)").html());
	$("#cfdd_manage_div_2 input").val($(obj).parent().parent().children("td:eq(3)").html());
}
function cfddManageQuery(){
	$(".msg2_span1").html("");
	$.ajax({
		url : "query_cfdd", //请求的url地址
		contentType : "application/json; charset=utf-8",
		dataType : "json", //返回格式为json
		type : "POST", //请求方式
		data : JSON.stringify({
			'cfdd' : ""
		}),
		beforeSend : function() {
		},
		success : function(data) {
			if(data.cfdds.length > 0){
				var str = '';
				for(var i = 0;i < data.cfdds.length;i++){
					str += "<tr><td>" + (i+1) + "</td><td>" 
					+ data.cfdds[i].cfdd 
					+ "</td><td><button type='button' class='btn btn-warning' data-toggle='modal' data-target='#btn_change_cfdd' onclick='btnChangeCfdd(this)'>修改</button>&nbsp&nbsp/&nbsp&nbsp<button type='button' class='btn btn-danger' onclick='btnDeleteCfdd(this)'>删除</button></td><td style='display: none'>"+ data.cfdds[i].id +"</td></tr>"
				}
				$("#cfdd_manage_div_table_tbody").html(str);
			}else{
				$("#cfdd_manage_div_table_tbody").html("没有数据...");
			}
		},
		error : function(req) {
			alert(JSON.stringify(req));
			alert("  error  请联系开发人员 ！");
		}
	});
	return false;
}
$("#btn_add_cfdd_form").submit(function() {
	$(".msg2_span1").html("");
	$(".msg2_span2").html("");
	$.ajax({
		url : "add_cfdd", //请求的url地址
		contentType : "application/json; charset=utf-8",
		dataType : "json", //返回格式为json
		type : "POST", //请求方式
		data : JSON.stringify({
			'cfdd' : $(
					"#btn_add_cfdd_form input[ name='cfdd_name' ] ")
					.val()
		}),
		beforeSend : function() {
		},
		success : function(data) {
			if (data.isSuccess) {
				$(".msg2_span1").html("新增成功...");
				$("#btn_add_cfdd").modal('hide');
				cfddManageQuery();
			} else {
				$(".msg2_span1").html("该地点已经存在...");
			}
		},
		error : function(req) {
			alert("  error  请联系开发人员 ！");
		}
	});
	return false;
});
</script>
</html>